import { request } from 'umi';
import type { CurrentUser, NoticeIconData, UserListItem } from './API.d';

class U {}

export async function query() {
  return request<CurrentUser[]>('/api/users');
}

export async function queryCurrent() {
  const token = localStorage.getItem('pl_token');
  if (token) {
    return {
      name: '管理员',
      access: 'admin',
      avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
    };
  }
  return undefined;
}

export async function queryNotices(): Promise<any> {
  return request<{ data: NoticeIconData[] }>('/api/notices');
}

export async function queryUserList(
  params: U & { pageSize?: number; current?: number; keyword?: string },
) {
  return request('/parkinglot/user/queryUserList', {
    method: 'POST',
    data: params,
  });
}

export async function addWalletUser(params: UserListItem) {
  return request('/parkinglot/user/addWalletUser', {
    method: 'POST',
    data: params,
  });
}

export async function addUser(params: UserListItem) {
  return request('/parkinglot/user/addUser', {
    method: 'POST',
    data: params,
  });
}

export async function removeUser(params: number[]) {
  return request('/parkinglot/user/removeUser', {
    method: 'POST',
    data: params,
  });
}

export async function frozenUser(params: number[]) {
  return request('/parkinglot/user/frozenUser', {
    method: 'POST',
    data: params,
  });
}

export async function thawUser(params: number[]) {
  return request('/parkinglot/user/thawUser', {
    method: 'POST',
    data: params,
  });
}

export async function updateUser(params: UserListItem) {
  return request('/parkinglot/user/updateUser', {
    method: 'POST',
    data: params,
  });
}
